package ru.spies.forms;

import javax.servlet.http.Cookie;

import ru.spies.content.DeleteContent;
import ru.spies.content.SystemContent;

public class DeleteForm extends FormCreator {

	private static DeleteForm statThis;
	
	private static final String DELETE_FORM_FUNC_NAMES_ARRAY[]={
		"Удалить документы","Удалить задания","Отменить задания агентам",
		"Уволить агентов", "Расформировать отделы","Покинуть страны",
		"Удалить тип секретности","Удалить типы заданий"
	};
	
	private DeleteForm() {
		setCookieName(LastCookies.COOKIE_NAME_FORM_FOR_WORK);
	}
	
	public static DeleteForm getInstance(){
		if (statThis==null){
			statThis = new DeleteForm();
		}
		return statThis;
	}

	@Override
	protected ICookie childCookieWork(Cookie cookie) {
		if (Integer.valueOf(cookie.getValue())==EDBTables.COUNTRY.ordinal()){
			return EDBTables.COUNTRY;
		}
		if (Integer.valueOf(cookie.getValue())==EDBTables.AGENT.ordinal()){
			return EDBTables.AGENT;
		}
		if (Integer.valueOf(cookie.getValue())==EDBTables.DEPARTMENT.ordinal()){
			return EDBTables.DEPARTMENT;
		}	
		if (Integer.valueOf(cookie.getValue())==EDBTables.AGENT_AND_TASK.ordinal()){
			return EDBTables.AGENT_AND_TASK;
		}	
		if (Integer.valueOf(cookie.getValue())==EDBTables.DOCUMENT.ordinal()){
			return EDBTables.DOCUMENT;
		}	
		if (Integer.valueOf(cookie.getValue())==EDBTables.IMPORTANCE.ordinal()){
			return EDBTables.IMPORTANCE;
		}	
		if (Integer.valueOf(cookie.getValue())==EDBTables.TASK.ordinal()){
			return EDBTables.TASK;
		}	
		if (Integer.valueOf(cookie.getValue())==EDBTables.TASK_TYPE.ordinal()){
			return EDBTables.TASK_TYPE;
		}		
		return null;
	}

	@Override
	protected String workWithCookieValue(ICookie cook) {
		EDBTables func = (EDBTables) cook;
		LastCookies.getInstance().setLastTable(func);
		switch (func) {
		case COUNTRY:
			return createDeleteCountryForm();
		case AGENT:
			return createDeleteAgentForm();
		case AGENT_AND_TASK:
			return createDeleteAgentAndTaskForm();
		case DEPARTMENT:
			return createDeleteDepartmentForm();
		case DOCUMENT:
			return createDeleteDocumentForm();
		case IMPORTANCE:
			return createDeleteImportanceForm();
		case TASK:
			return createDeleteTaskForm();
		case TASK_TYPE:
			return createDeleteTaskTypeForm();
		default:
			return createForm(SOME_ERRORS);
		}
	}

	private String createDeleteTaskTypeForm() {
		return createFormWithPostMethod(DeleteContent.getInstance().formDeleteTaskTypeContent(), SHOW_RESULT_LINK);
	}

	private String createDeleteTaskForm() {
		return createFormWithPostMethod(DeleteContent.getInstance().formDeleteTaskContent(),SHOW_RESULT_LINK);
	}

	private String createDeleteImportanceForm() {
		return createFormWithPostMethod(DeleteContent.getInstance().formDeleteImportanceContent(), SHOW_RESULT_LINK);
	}

	private String createDeleteDocumentForm() {
		return createFormWithPostMethod(DeleteContent.getInstance().formDeleteDocumentContent(),SHOW_RESULT_LINK);
	}

	private String createDeleteDepartmentForm() {
		return createFormWithPostMethod(DeleteContent.getInstance().formDeleteDepartmentContent(), SHOW_RESULT_LINK);
	}

	private String createDeleteAgentAndTaskForm() {
		return createFormWithPostMethod(DeleteContent.getInstance().formDeleteAgentAndTaskContent(), SHOW_RESULT_LINK);
	}

	private String createDeleteAgentForm() {
		return createFormWithPostMethod(DeleteContent.getInstance().formDeleteAgentContent(), SHOW_RESULT_LINK);
	}

	private String createDeleteCountryForm() {
		return createFormWithPostMethod(DeleteContent.getInstance().formDeleteCountryContent(), SHOW_RESULT_LINK);
	}

	@Override
	public String createThisForm() {
		return createForm(SystemContent.getInstance().formForWorkContent(DELETE_FORM_FUNC_NAMES_ARRAY));
	}

}
